//
//  ChangeNameViewController.m
//  Luxury
//
//  Created by DCQ on 2018/5/19.
//  Copyright © 2018年 ZNXZ. All rights reserved.
//

#import "ChangeNameViewController.h"
#import "CustomerServiceViewController.h"
#import "UserInfoModel.h"
@interface ChangeNameViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameTextFeild;

@end

@implementation ChangeNameViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNavigationItemTitle:@"修改昵称"];
    [self setupRightItem];
    self.nameTextFeild.placeholder = UserInfo.nickname;
    
}

- (void)setupRightItem{
    
    UIImage *rightBtnImg = [[UIImage imageNamed:@"bottom_kefu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]   ;
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithImage:rightBtnImg style:UIBarButtonItemStylePlain target:self action:@selector(rightAction)];
    self.navigationItem.rightBarButtonItem = rightItem;
}

- (void)rightAction{
    CustomerServiceViewController * customerServiceVC = [[CustomerServiceViewController alloc]init];
    [self pushViewController:customerServiceVC];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)completeAction:(id)sender {
    if (![self.nameTextFeild.text isEqualToString:UserInfo.nickname]) {
        NSDictionary * params = @{@"token":UserInfo.userToken, @"nickname":self.nameTextFeild.text};
        WEAKSELF
        [[MainApi sharedInstance] postPath:@"User/profile" params:params  resultBlock:^(NSDictionary *responseObject, NSError *error) {
            STRONGSELF
            UserInfo.nickname = strongSelf.nameTextFeild.text;
            if (strongSelf.changeBlock) {
                strongSelf.changeBlock(strongSelf.nameTextFeild.text);
            }
            [self.navigationController popViewControllerAnimated:YES];
        }];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
